package com.visual.luckydemo;

import android.content.Context;
import android.util.Log;
import android.widget.Toast;

import java.text.SimpleDateFormat;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;

public class LogUtil {
    public static final String KERMIT_TAG = "kermit";
    public static final String TAG = "iCast";
    private static Toast toast;
    public static boolean DEBUG = BuildConfig.DEBUG;
    final static int DEBUG_LEVEL = 3;
    public final static boolean STRICT_MODE = false;
    private static SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.CHINA);// 设置日期格式
    public static Map<String, Integer> mapLogDebugCtrl = new HashMap<String, Integer>();

    static {
        //LogUtil.mapLogDebugCtrl.put(PFUtil.class.getSimpleName(), 2);
    }

    public static void Logi(final String tag, String msg) {

        if (DEBUG == false || tag == null || msg == null) {
            return;
        }
        if (LogUtil.mapLogDebugCtrl.get(tag) != null) {
            if (LogUtil.mapLogDebugCtrl.get(tag) < DEBUG_LEVEL)
                return;
        }
        Log.v(tag, msg);
    }

    public static void Logv(final String tag, String msg) {

        if (DEBUG == false || tag == null || msg == null) {
            return;
        }
        if (LogUtil.mapLogDebugCtrl.get(tag) != null) {
            if (LogUtil.mapLogDebugCtrl.get(tag) < DEBUG_LEVEL)
                return;
        }
        Log.v(tag, msg);
    }

    public static void Logd(final String tag, String msg) {
        if (DEBUG == false || tag == null || msg == null) {
            return;
        }
        if (LogUtil.mapLogDebugCtrl.get(tag) != null) {
            if (LogUtil.mapLogDebugCtrl.get(tag) < DEBUG_LEVEL)
                return;
        }
        Log.d(tag, msg);
    }

    public static void Loge(final String tag, String msg) {
        if (tag == null || msg == null) {
            return;
        }
        Log.e(tag, msg);
    }

    public static Toast toast(Context context, String text) {
        if (toast == null) {
            toast = Toast.makeText(context, text, Toast.LENGTH_SHORT);
        } else {
            toast.setText(text);
        }
        toast.show();
        return toast;
    }

    public static Toast toast(Context context, int text) {
        if (toast == null) {
            toast = Toast.makeText(context, text, Toast.LENGTH_SHORT);
        } else {
            toast.setText(text);
        }
        toast.show();
        return toast;
    }

    public static void cancelToast() {
        if (toast != null) {
            toast.cancel();
            toast = null;
        }
    }
}
